package cn.szzsi._web;

import cn.szzsi.interceptor.CommonInterceptor;
import cn.szzsi.interceptor.JSSDKInterceptor;
import cn.szzsi.interceptor.WechatLoginInterceptor;
import cn.szzsi.service.FavoriteProductService;
import cn.szzsi.service.ProductService;
import cn.szzsi.common.bean.dto.Msg;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.*;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.json.Json;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前台类 - 商品
 * 
 */
public class ProductController extends BaseWebController<Product> {
	
	private ProductCategory productCategory;
	private String orderType;// 排序类型
	private String viewType;// 查看类型
	
	
	private List<Product> bestProductList;//是否精品
	private List<Product> hotProductList;//是否最热
	private List<Product> newProductList;//是否最新
	private List<ProductCategory> pathList;
	private Page<Product> pager;
	private String path;
	private String uid;//用户的shopId对应商户的id(uid),商户的shopId为"0"
	private List<Product> products;//全部商品
	// 列表
	public void list() {
		uid=getPara("shopId");
		String productCategory_id = getPara("id","");
		orderType = getPara("orderType","");
		viewType = getPara("viewType","");
		int pageNumber = getParaToInt("pageNumber",1);
		int pageSize = getParaToInt("pageSize",Product.DEFAULT_PRODUCT_LIST_PAGE_SIZE);
		
		if(StrKit.notBlank(productCategory_id)){
			productCategory = ProductCategory.dao.findById(productCategory_id);
		}
		if (productCategory == null){
			addActionError("未找到内容");
			return;
		}						
		bestProductList = Product.dao.getBusinessBestProductList(uid,productCategory_id, Product.MAX_BEST_PRODUCT_LIST_COUNT);
		hotProductList = Product.dao.getBusinessHotProductList(uid,productCategory_id, Product.MAX_HOT_PRODUCT_LIST_COUNT);
		newProductList = Product.dao.getBusinessNewProductList(uid,productCategory_id, Product.MAX_NEW_PRODUCT_LIST_COUNT);
		pathList = ProductCategory.dao.getBusinessProductCategoryPathList(uid,productCategory);
		
		if (StringUtils.equalsIgnoreCase(orderType, "priceAsc")) {
			pager = Product.dao.categorySearch(pageNumber, pageSize,productCategory,"price", OrderType.asc);
		} else if (StringUtils.equalsIgnoreCase(orderType, "priceDesc")) {
			pager = Product.dao.categorySearch(pageNumber, pageSize,productCategory,"price", OrderType.desc);
		} else if (StringUtils.equalsIgnoreCase(orderType, "dateAsc")) {
			pager = Product.dao.categorySearch(pageNumber, pageSize,productCategory,"p.createDate", OrderType.asc);
		} else {
			pager = Product.dao.categorySearch(pageNumber, pageSize,productCategory,"p.createDate", OrderType.desc);
		}
		
		setAttr("pager", pager);
		setAttr("productCategory", productCategory);
		setAttr("rootProductCategoryList", getRootProductCategoryList(uid));
		setAttr("hotProductList", hotProductList);
		setAttr("bestProductList", bestProductList);
		setAttr("newProductList", newProductList);
		setAttr("pathList", pathList);
		setAttr("shopId",uid);

		if(StringUtils.equalsIgnoreCase(viewType, "tableType")){
			getTemplatePath(uid,"product_table_list");
		}else{
			getTemplatePath(uid,"product_picture_list");
		}

	}
	//查询商品列表(wap版本,表单提交方式)
	@Clear
	@Before(CommonInterceptor.class)
	public void goodList(){
		uid=getPara("shopId");
		String keyword=getPara("keyword");
		String productCategory_id=getPara("productCategory_id");//商品分类id
		if(StrKit.notBlank(productCategory_id)){
			productCategory = ProductCategory.dao.findById(productCategory_id);
		}

		List<ProductCategory> businessProductCategoryList= ProductCategory.dao.getByUid(uid);
		setAttr("businessProductCategoryList",businessProductCategoryList);

		String sort=getPara("sort");//排序方式:0-销量,1-时间,2-价格
		String sortType0=getPara("sortType0");//销量排序类型:asc升序,desc降序
		String sortType1=getPara("sortType1");//时间排序类型:asc升序,desc降序
		String sortType2=getPara("sortType2");//价格排序类型:asc升序,desc降序
		if(sort==null ){//默认按照上架时间降序排序
			sortType1="desc";
			if(StrKit.notBlank(keyword)){
				products=Product.dao.getByKeyword(uid,"createDate",sortType1,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				products=Product.dao.getRootProductCategory(productCategory,"p.createDate",sortType1);
			}else{
				products=Product.dao.getByUid(uid,"createDate",sortType1);
			}
			setAttr("sort","1");
			setAttr("sortType1","asc");
			setAttr("sortType2","asc");
		}else if("1".equals(sort)){//时间排序
			if(StrKit.notBlank(keyword)){
				products=Product.dao.getByKeyword(uid,"createDate",sortType1,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				products=Product.dao.getRootProductCategory(productCategory,"p.createDate",sortType1);
			}else{
				products=Product.dao.getByUid(uid,"createDate",sortType1);
			}
			if("asc".equalsIgnoreCase(sortType1)){
				setAttr("sortType1","desc");
			}else{
				setAttr("sortType1","asc");
			}
			setAttr("sort","1");
			setAttr("sortType0","desc");
			setAttr("sortType2","asc");
		}else if("2".equals(sort)){//价格排序
			if(StrKit.notBlank(keyword)){
				products=Product.dao.getByKeyword(uid,"price",sortType2,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				products=Product.dao.getRootProductCategory(productCategory,"price",sortType2);
			}else{
				products=Product.dao.getByUid(uid,"price",sortType2);
			}
			if("asc".equalsIgnoreCase(sortType2)){
				setAttr("sortType2","desc");
			}else{
				setAttr("sortType2","asc");
			}
			setAttr("sort","2");
			setAttr("sortType0","desc");
			setAttr("sortType1","desc");
		}
		path=CommonUtil.getPathByUidAndType(uid,CommonUtil.isMobileDevice(getRequest()));//获取模板路径
		setAttr("keyword",keyword);
		setAttr("shopId",uid);
		setAttr("products",products);
		setAttr("path",path);
		if(StrKit.isBlank(productCategory_id)){
			if(businessProductCategoryList!=null&&businessProductCategoryList.size()>0)
				productCategory_id = businessProductCategoryList.get(0).get("id");
		}
		setAttr("productCategory_id",productCategory_id);
		getTemplatePath(uid,"product_table_list");

	}


	//查询商品列表(异步查询)
	//1.页面(无数据)
	@Clear
	@Before(CommonInterceptor.class)
	public void goodListForm(){
		uid=getPara("shopId");
		String keyword=getPara("keyword");
		String productCategory_id=getPara("productCategory_id");//商品分类id
		if(StrKit.notBlank(productCategory_id)){
			productCategory = ProductCategory.dao.findById(productCategory_id);
		}

		List<ProductCategory> businessProductCategoryList= ProductCategory.dao.getByUid(uid);
		setAttr("businessProductCategoryList",businessProductCategoryList);

		String sort=getPara("sort");//排序方式:0-销量,1-时间,2-价格
		String sortType0=getPara("sortType0");//销量排序类型:asc升序,desc降序
		String sortType1=getPara("sortType1");//时间排序类型:asc升序,desc降序
		String sortType2=getPara("sortType2");//价格排序类型:asc升序,desc降序
		if(sort==null ){//默认按照上架时间降序排序
			setAttr("sort","1");
			setAttr("sortType1","asc");
			setAttr("sortType2","asc");
		}else if("1".equals(sort)){//时间排序
			if("asc".equalsIgnoreCase(sortType1)){
				setAttr("sortType1","desc");
			}else{
				setAttr("sortType1","asc");
			}
			setAttr("sort","1");
			setAttr("sortType0","desc");
			setAttr("sortType2","asc");
		}else if("2".equals(sort)){//价格排序
			if("asc".equalsIgnoreCase(sortType2)){
				setAttr("sortType2","desc");
			}else{
				setAttr("sortType2","asc");
			}
			setAttr("sort","2");
			setAttr("sortType0","desc");
			setAttr("sortType1","desc");
		}
		path=CommonUtil.getPathByUidAndType(uid,CommonUtil.isMobileDevice(getRequest()));//获取模板路径
		setAttr("keyword",keyword);
		setAttr("shopId",uid);
		setAttr("products",products);
		setAttr("path",path);
		setAttr("productCategory_id",productCategory_id);
		getTemplatePath(uid,"product_table_list");
	}
	@Clear
	@Before(CommonInterceptor.class)
	public void ajaxgoodList(){
		int pageNumber=getParaToInt("pageNumber", 1);//第几页,默认1
		int pageSize=getParaToInt("pageSize", 10);//每页的数量,默认10
		Map<String,Object> map=new HashMap<String,Object>();//返回map集合
		uid=getPara("shopId");
		String keyword=getPara("keyword");
		String productCategory_id=getPara("productCategory_id");//商品分类id
		if(StrKit.notBlank(productCategory_id)){
			productCategory = ProductCategory.dao.findById(productCategory_id);
		}
		String sort=getPara("sort");//排序方式:0-销量,1-时间,2-价格
		String sortType0=getPara("sortType0");//销量排序类型:asc升序,desc降序
		String sortType1=getPara("sortType1");//时间排序类型:asc升序,desc降序
		String sortType2=getPara("sortType2");//价格排序类型:asc升序,desc降序
		if(sort==null ){//默认按照上架时间降序排序
			sortType1="desc";
			if(StrKit.notBlank(keyword)){
				pager= ProductService.service.getByKeyword(pageNumber,pageSize,uid,"createDate",sortType1,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				pager= ProductService.service.getRootProductCategory(pageNumber,pageSize,productCategory,"p.createDate",sortType1);
			}else{
				pager= ProductService.service.getByUid(pageNumber,pageSize,uid,"createDate",sortType1);
			}
		}else if("1".equals(sort)){//时间排序
			if(StrKit.notBlank(keyword)){
				pager= ProductService.service.getByKeyword(pageNumber,pageSize,uid,"createDate",sortType1,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				pager= ProductService.service.getRootProductCategory(pageNumber,pageSize,productCategory,"p.createDate",sortType1);

			}else{
				pager= ProductService.service.getByUid(pageNumber,pageSize,uid,"createDate",sortType1);
			}
		}else if("2".equals(sort)){//价格排序
			if(StrKit.notBlank(keyword)){
				pager= ProductService.service.getByKeyword(pageNumber,pageSize,uid,"price",sortType2,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				pager= ProductService.service.getRootProductCategory(pageNumber,pageSize,productCategory,"p.price",sortType2);
			}else{
				pager= ProductService.service.getByUid(pageNumber,pageSize,uid,"price",sortType2);
			}
		}
		map.put("pager",pager);
		//System.out.println(Msg.success(map));
		renderJson(Msg.success(map));
	}


	//查询商品列表(异步查询)
	//1.页面(无数据)
	@Clear
	@Before(CommonInterceptor.class)
	public void goodListFormAll(){
		String keyword=getPara("keyword");
		String productCategory_id=getPara("productCategory_id");//商品分类id
		if(StrKit.notBlank(productCategory_id)){
			productCategory = ProductCategory.dao.findById(productCategory_id);
		}

		List<ProductCategory> businessProductCategoryList= ProductCategory.dao.getAll();
		setAttr("businessProductCategoryList",businessProductCategoryList);

		String sort=getPara("sort");//排序方式:0-销量,1-时间,2-价格
		String sortType0=getPara("sortType0");//销量排序类型:asc升序,desc降序
		String sortType1=getPara("sortType1");//时间排序类型:asc升序,desc降序
		String sortType2=getPara("sortType2");//价格排序类型:asc升序,desc降序
		if(sort==null ){//默认按照上架时间降序排序
			setAttr("sort","1");
			setAttr("sortType1","asc");
			setAttr("sortType2","asc");
		}else if("1".equals(sort)){//时间排序
			if("asc".equalsIgnoreCase(sortType1)){
				setAttr("sortType1","desc");
			}else{
				setAttr("sortType1","asc");
			}
			setAttr("sort","1");
			setAttr("sortType0","desc");
			setAttr("sortType2","asc");
		}else if("2".equals(sort)){//价格排序
			if("asc".equalsIgnoreCase(sortType2)){
				setAttr("sortType2","desc");
			}else{
				setAttr("sortType2","asc");
			}
			setAttr("sort","2");
			setAttr("sortType0","desc");
			setAttr("sortType1","desc");
		}
		setAttr("keyword",keyword);
		setAttr("shopId",uid);
		setAttr("products",products);
		setAttr("productCategory_id",productCategory_id);
		wapTemplatePath("product_table_list.html");
	}
	@Clear
	@Before(CommonInterceptor.class)
	public void ajaxgoodListAll(){
		int pageNumber=getParaToInt("pageNumber", 1);//第几页,默认1
		int pageSize=getParaToInt("pageSize", 10);//每页的数量,默认10
		Map<String,Object> map=new HashMap<String,Object>();//返回map集合
		String keyword=getPara("keyword");
		String productCategory_id=getPara("productCategory_id");//商品分类id
		if(StrKit.notBlank(productCategory_id)){
			productCategory = ProductCategory.dao.findById(productCategory_id);
		}
		String sort=getPara("sort");//排序方式:0-销量,1-时间,2-价格
		String sortType0=getPara("sortType0");//销量排序类型:asc升序,desc降序
		String sortType1=getPara("sortType1");//时间排序类型:asc升序,desc降序
		String sortType2=getPara("sortType2");//价格排序类型:asc升序,desc降序
		if(sort==null ){//默认按照上架时间降序排序
			sortType1="desc";
			if(StrKit.notBlank(keyword)){
				pager= ProductService.service.getByKeywordPlateForm(pageNumber,pageSize,"createDate",sortType1,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				pager= ProductService.service.getRootProductCategory(pageNumber,pageSize,productCategory,"p.createDate",sortType1);
			}else{
				pager= ProductService.service.getAll(pageNumber,pageSize,"createDate",sortType1);
			}
		}else if("1".equals(sort)){//时间排序
			if(StrKit.notBlank(keyword)){
				pager= ProductService.service.getByKeywordPlateForm(pageNumber,pageSize,"createDate",sortType1,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				pager= ProductService.service.getRootProductCategory(pageNumber,pageSize,productCategory,"p.createDate",sortType1);

			}else{
				pager= ProductService.service.getAll(pageNumber,pageSize,"createDate",sortType1);
			}
		}else if("2".equals(sort)){//价格排序
			if(StrKit.notBlank(keyword)){
				pager= ProductService.service.getByKeywordPlateForm(pageNumber,pageSize,"price",sortType2,keyword);
			}else if(StrKit.notBlank(productCategory_id)){//按照商品分类进行查询
				pager= ProductService.service.getRootProductCategory(pageNumber,pageSize,productCategory,"p.price",sortType2);
			}else{
				pager= ProductService.service.getAll(pageNumber,pageSize,"price",sortType2);
			}
		}
		map.put("pager",pager);
		System.out.println(Msg.success(map));
		renderJson(Msg.success(map));
	}

	//查询商品分类(wap版本)
	@Clear
	@Before(CommonInterceptor.class)
	public void goodCategory(){
		uid=getPara("shopId");
		List<ProductCategory> businessProductCategoryList= ProductCategory.dao.getByUid(uid);
		setAttr("businessProductCategoryList",businessProductCategoryList);
		List<Admanage> businessAdImgList= Admanage.dao.getAdImageByUid(uid);
		setAttr("businessAdImgList",businessAdImgList);
		path=CommonUtil.getPathByUidAndType(uid,CommonUtil.isMobileDevice(getRequest()));//获取模板路径
		setAttr("shopId",uid);
		setAttr("path",path);

		Member member=getLoginMember();
		setAttr("loginMember",member);
		getTemplatePath(uid,"good_category");
	}

	//查询商品分类(wap版本)
	@Clear
	@Before(CommonInterceptor.class)
	public void goodCategoryPlateform(){
		List<ProductCategory> businessProductCategoryList= ProductCategory.dao.getAll();
		setAttr("businessProductCategoryList",businessProductCategoryList);
		Member member=getLoginMember();
		setAttr("loginMember",member);
		wapTemplatePath("good_category.html");
	}

	//wap商品详情页
	@Clear
	public void detail(){
		String id=getPara("id");
		uid=getPara("shopId");
		Product product=Product.dao.findById(id);
		String productCategory_id=product.getStr("productCategory_id");//商品分类id
		productCategory = ProductCategory.dao.findById(productCategory_id);

		//查看商品评价
		List<ProductEvaluate> evaluateList= ProductEvaluate.dao.getEvaluateList(id);
		setAttr("rootProductCategoryList", getRootProductCategoryList(uid));
		setAttr("evaluateList",evaluateList);
		//获取同类商品
		List<Product> categoryProduct=Product.dao.getRootProductCategory(productCategory,"p.createDate","desc");
		path=CommonUtil.getPathByUidAndType(uid,CommonUtil.isMobileDevice(getRequest()));//获取模板路径

		bestProductList = Product.dao.getBusinessBestProductList(uid,Product.MAX_BEST_PRODUCT_LIST_COUNT);
		hotProductList = Product.dao.getBusinessHotProductList(uid,Product.MAX_HOT_PRODUCT_LIST_COUNT);
		newProductList = Product.dao.getBusinessNewProductList(uid,Product.MAX_NEW_PRODUCT_LIST_COUNT);
		pathList = ProductCategory.dao.getBusinessProductCategoryPathList(uid,productCategory);
		setAttr("pathList", pathList);
		setAttr("hotProductList", hotProductList);
		setAttr("bestProductList", bestProductList);
		setAttr("newProductList", newProductList);
		setAttr("product",product);
		setAttr("categoryProduct",categoryProduct);
		setAttr("shopId",uid);
		setAttr("path",path);
		getTemplatePath(uid,"product_content");
	}
	//wap商品详情页
	@Clear
	@Before({CommonInterceptor.class,WechatLoginInterceptor.class, JSSDKInterceptor.class})
	public void detailWap(){
		String id=getPara("id");
		uid=getPara("shopId");
		Product product=Product.dao.findById(id);
		String productCategory_id=product.getProductcategoryId();//商品分类id
		productCategory = ProductCategory.dao.findById(productCategory_id);

		//查看商品评价
		List<ProductEvaluate> evaluateList= ProductEvaluate.dao.getEvaluateList(id);
		setAttr("evaluateList",evaluateList);

		//查询该商品已付款数量
		List<Record> list= Db.find("select count(*)count from mall_order_item om JOIN mall_orders os ON om.order_id=os.id and om.product_id=? and os.paymentStatus='2'",id);
		setAttr("paymentCount",list.get(0).get("count"));

		//获取同类商品(看了又看)
		List<Product> categoryProduct=Product.dao.getRootProductCategory(productCategory,"p.createDate","desc",3);
		//此商品分类下的所有热卖商品集合(买了又买)
		List<Product> hotProduct=Product.dao.getBusinessHotProductList(uid,productCategory_id,3);

		//查看该商品是否被当前用户收藏
		Member loginMember=getLoginMember();
		if(loginMember==null){
			setAttr("hasFavorite",false);
		}else{
			FavoriteProduct favoriteProduct= FavoriteProduct.dao.getByMemberIdAndProductId(loginMember.getId(),id);
			if(favoriteProduct==null){
				setAttr("hasFavorite",false);
			}else{
				setAttr("hasFavorite",true);
			}
		}
		setAttr("hotProduct",hotProduct);
		setAttr("categoryProduct",categoryProduct);
		setAttr("product",product);
		if(product.getProductImageList().size()>0){
			setAttr("shareImg",product.getProductImageList().get(0).getSourceProductImagePath());
		}
		//setAttr("shareImg",product.getProductImageList())
		setAttr("shopId",uid);
		getTemplatePath(uid,"detail");
	}


	//wap商品详情页
	@Clear
	@Before({CommonInterceptor.class,WechatLoginInterceptor.class, JSSDKInterceptor.class})
	public void test(){
		String id=getPara("id");
		uid=getPara("shopId");
		Product product=Product.dao.findById(id);
		String productCategory_id=product.getStr("productCategory_id");//商品分类id
		productCategory = ProductCategory.dao.findById(productCategory_id);

		//查看商品评价
		//List<ProductEvaluate> evaluateList= ProductEvaluate.dao.getEvaluateList(id);
		List<ProductEvaluate> evaluateList= ProductEvaluate.dao.getEvaluateList(product);
		setAttr("evaluateList",evaluateList);

		//查询该商品已付款数量
		List<Record> list= Db.find("select count(*)count from mall_order_item om JOIN mall_orders os ON om.order_id=os.id and om.product_id=? and os.paymentStatus='2'",id);
		setAttr("paymentCount",list.get(0).get("count"));

		//获取同类商品(看了又看)
		List<Product> categoryProduct=Product.dao.getRootProductCategory(productCategory,"p.createDate","desc",3);
		//此商品分类下的所有热卖商品集合(买了又买)
		List<Product> hotProduct=Product.dao.getBusinessHotProductList(uid,productCategory_id,3);

		//查看该商品是否被当前用户收藏
		Member loginMember=getLoginMember();
		if(loginMember==null){
			setAttr("hasFavorite",false);
		}else{
			FavoriteProduct favoriteProduct= FavoriteProduct.dao.getByMemberIdAndProductId(loginMember.getId(),id);
			if(favoriteProduct==null){
				setAttr("hasFavorite",false);
			}else{
				setAttr("hasFavorite",true);
			}
		}
		setAttr("hotProduct",hotProduct);
		setAttr("categoryProduct",categoryProduct);
		setAttr("product",product);
		if(product.getProductImageList()!=null && product.getProductImageList().size()>0){
			setAttr("shareImg",product.getProductImageList().get(0).getSourceProductImagePath());
		}
		//setAttr("shareImg",product.getProductImageList())
		setAttr("shopId",uid);
		getTemplatePath(uid,"test");
	}

	// 搜索
	public void search() {
		uid=getPara("shopId");
		String keyword = getPara("keyword","");
		orderType = getPara("orderType","");
		viewType = getPara("viewType","");
		int pageNumber = getParaToInt("pageNumber",1);
		int pageSize = getParaToInt("pageSize",Product.DEFAULT_PRODUCT_LIST_PAGE_SIZE);

		bestProductList = Product.dao.getBusinessBestProductList(uid,Product.MAX_BEST_PRODUCT_LIST_COUNT);
		hotProductList = Product.dao.getBusinessHotProductList(uid,Product.MAX_HOT_PRODUCT_LIST_COUNT);
		newProductList = Product.dao.getBusinessNewProductList(uid,Product.MAX_NEW_PRODUCT_LIST_COUNT);
		
		if (StringUtils.equalsIgnoreCase(orderType, "priceAsc")) {
			pager = Product.dao.businessSearch(uid,pageNumber, pageSize,keyword,"price", OrderType.asc);
		} else if (StringUtils.equalsIgnoreCase(orderType, "priceDesc")) {
			pager = Product.dao.businessSearch(uid,pageNumber, pageSize,keyword,"price", OrderType.desc);
		} else if (StringUtils.equalsIgnoreCase(orderType, "dateAsc")) {
			pager = Product.dao.businessSearch(uid,pageNumber, pageSize,keyword,"createDate", OrderType.asc);
		} else {
			pager = Product.dao.businessSearch(uid,pageNumber, pageSize,keyword,"createDate", OrderType.desc);
		}
		
		setAttr("pager", pager);
		setAttr("rootProductCategoryList", getRootProductCategoryList(uid));
		setAttr("hotProductList", hotProductList);
		setAttr("bestProductList", bestProductList);
		setAttr("newProductList", newProductList);
		setAttr("shopId",uid);
		setAttr("keyword",keyword);
		path=CommonUtil.getPathByUidAndType(uid,CommonUtil.isMobileDevice(getRequest()));//获取模板路径
		setAttr("path",path);
		if(StringUtils.equalsIgnoreCase(viewType, "tableType")){
			getTemplatePath(uid,"product_table_search");
		}else{
			getTemplatePath(uid,"product_picture_search");
		}

	}
	
	public List<ProductCategory> getRootProductCategoryList(String uid) {
		return ProductCategory.dao.getBusinessRootProductCategoryList(uid);
	}
	
	public void addActionError(String error){
		setAttr("errorMessages", error);
		render(CommonUtil.TEMPLATE_PATH+"/shop/error.html");
	}
	
}
